package com.flyu.myThread.Sleep;

import java.text.SimpleDateFormat;
import java.util.Date;

// 模拟倒计时
public class TestSleep {
    public static void main(String[] args) throws InterruptedException {
//        tenDown();
        curTime();
    }
    // 倒数10个数
    public static void tenDown() throws InterruptedException {
        int num = 10;
        while (true){
            Thread.sleep(1000);
            System.out.println(num--);
            if (num <= 0){
                break;
            }
        }
    }
    // 打印当前时间
    public static void curTime() throws InterruptedException {
        int num = 10;
        Date date = new Date(System.currentTimeMillis());
        while (true){
            Thread.sleep(1000);
            System.out.println(new SimpleDateFormat("HH:mm:ss").format(date));
            date = new Date(System.currentTimeMillis());
            num--;
            if (num <= 0){
                break;
            }
        }

    }
}
